<?php
/**
 * Created by PhpStorm.
 * User: Ason
 * Date: 15-6-29
 * Time: 上午9:31
 */
?>
<div class="modal-dialog modal-lg">
	<div class="modal-content">

		<div class="modal-header bordered-bottom-3 bordered-orange">
			<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
					class="sr-only">Close</span></button>
			<h4 class="modal-title"><span class="glyphicon glyphicon-pencil"></span>编辑菜单项</h4>
		</div>
		<div class="modal-body">
			<!--错误提示 BEGIN-->
				<div id="edit_alert" class="alert text-center" style="display:none;"></div>
			<!--错误提示 END-->
			<form class="form">
				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">名称</label>

					<div class="col-md-10">
						<div class="form-group">
							<input type="text" class="form-control" name="m_name" id="m_name" placeholder="菜单名" value="<?=$menu_info->name;?>">
						</div>
					</div>
				</div>

				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">图标</label>

					<div class="col-md-10">
						<div class="form-group">
							<input type="text" class="form-control" name="m_icon" id="m_icon" placeholder="图标" value="<?=$menu_info->icon;?>">
						</div>
					</div>
				</div>

				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">上级菜单</label>

					<select name="m_parent_id" id="m_parent_id">
						<option value="0">作为顶级</option>
					<?php foreach( $top_menu as $t ):?>
						<option value="<?=$t->id;?>" <?php if( $menu_info->parent_id ==$t->id ) echo "selected";?>><?=$t->name;?></option>
					<?php endforeach; ?>
					</select>
				</div>

				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">URL</label>

					<div class="col-md-10">
						<div class="form-group">
							<input type="text" class="form-control" name="m_url" id="m_url" placeholder="路径（ controller/method ）" value="<?=$menu_info->url;?>">
						</div>
					</div>
				</div>
				<div class="form-group clearfix form-bordered">
					<label class="control-label col-md-2">排序</label>

					<div class="col-md-10">
						<div class="form-group">
							<input type="number" class="form-control" name="m_order" id="m_order" placeholder="排序（数字越小越靠前）" value="<?=$menu_info->order;?>">
						</div>
					</div>
				</div>
			</form>

		</div>
		<div class="modal-footer">
			<div class="form-group text-right">
				<button class="btn btn-success" id="edit_menu">确认修改</button>&nbsp;&nbsp;&nbsp;&nbsp;
				<button class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>


	</div>
</div>
<script>
	$("#edit_menu").click(function(){

		$.post(
			"<?=site_url('navi/do_edit_menu')?>",
			{
				id:<?=$id;?>,
				name: $( "#m_name" ).val(),
				icon: $( "#m_icon" ).val(),
				parent_id: $( "#m_parent_id" ).val(),
				url: $( "#m_url" ).val(),
				order: $( "#m_order" ).val(),
			},
			function( json ){
				$( '#edit_alert' ).removeClass( 'alert-danger show').text('');
				data = eval( '(' + json + ')' );
				if( data.status == 'error' ){
					$('#edit_alert' ).addClass('alert-danger show').text( data.error );
				}else{
					$('#edit_alert' ).addClass('alert-success show').text( data.error );
					setTimeout( function(){
						window.location.reload();
					}, 2000);
				}
			}
		)
	});
</script>